package com.atu.servlet;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class ServletContext_1 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取配置信息区域对象
        ServletContext context = getServletConfig().getServletContext();
//        1、获取 web.xml 中配置的上下文参数 context-param
        System.out.println("username:"+context.getInitParameter("username"));
        System.out.println("password:"+context.getInitParameter("password"));
//        2、获取当前的工程路径，格式: /工程路径
        System.out.println("当前工程路径："+context.getContextPath());
//        3、获取工程部署后在服务器硬盘上的绝对路径
        System.out.println("当前工程绝对路径："+context.getRealPath("/"));
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }
}
